//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_DMA_H__
#define __ELASTOS_DMA_H__

#include <ddk.h>

INLINE virtaddr_t DzAllocDmaPages(uint_t uOrder)
{
    return DzAllocKernelPages(uOrder, AKPFlag_DMA);
}

INLINE virtaddr_t DzAllocDmaPage()        { return DzAllocDmaPages(0); }

INLINE void DzFreeDmaPages(virtaddr_t va, uint_t uOrder)
{
    DzFreeKernelPages(va, uOrder);
}

INLINE void DzFreeDmaPage(virtaddr_t va)  { DzFreeDmaPages(va, 0); }

enum DmaTransferMode
{
    DmaTransferMode_DeviceToMemory  = 0x01,
    DmaTransferMode_MemoryToDevice  = 0x02
};

//
// class DmaChannel
//
class DzDmaChannel
{
    friend class DmaController;

public:
    ECode RequestTransfer(
        DmaTransferMode mode, virtaddr_t vaBuffer, uint32_t uLength);

    ECode RequestTransfer(
        virtaddr_t vaDestBuffer, virtaddr_t vaSrcBuffer, uint32_t uLength);

    uint32_t GetTransferResidue();

    void Release();

private:
    bool_t  m_bBusy;
};

EXTERN ECode DzRequestDmaChannel(uint_t uNo, DzDmaChannel **ppDmaChannel);

#endif //__ELASTOS_DMA_H__
